% -------------------------------------------------------------------------
% 构造约束
%
% Copyright(C) 2015/04/29 by Chen Zhang, 
% School of Astronautics, Beihang University
% chenzhang.buaa@gmail.com
% -------------------------------------------------------------------------
function [c , ceq] = cons(xx , auxdata)
mu = auxdata.mu;
ri = auxdata.ri;
rf = auxdata.rf;
xi = xx(1); yi = xx(2); vxi = xx(3); vyi = xx(4); ti = xx(5); tf = xx(6);
xxi = [xi; yi; vxi; vyi];

options = odeset('AbsTol' , 1e-8 , 'RelTol' , 1e-8);
[~ , xx_temp] = ode113(@f4y , [ti , tf] , [xxi] , options , auxdata);
xf = xx_temp(end , 1); yf = xx_temp(end , 2);
vxf = xx_temp(end , 3); vyf = xx_temp(end , 4);

% 等式约束
ceq = [(xi + mu)^2 + yi^2 - ri^2;
    (xi + mu) * (vxi - yi) + yi * (vyi + xi + mu);
    (xf + mu - 1)^2 + yf^2 - rf^2;
    (xf + mu - 1) * (vxf - yf) + yf * (vyf + xf + mu - 1)];
% 不等式约束
c = [];
end
